<?php
/**
 *  Class extends from php captcha
 * @author tuanvd
 *
 */
require ('php-captcha.inc.php');
class PHP_Captcha_Exts extends PhpCaptcha {
	
	function PHP_Captcha_Exts($aFonts, $iWidth = CAPTCHA_WIDTH, $iHeight = CAPTCHA_HEIGHT) {
		parent::PhpCaptcha ( $aFonts, $iWidth, $iHeight );
	}
	
	function Create($sFilename = '', $key_session = null, $id = '') {
		if (parent::Create ( $sFilename, $id )) {
			$_SESSION [CAPTCHA_SESSION_ID . $key_session] = $_SESSION [CAPTCHA_SESSION_ID.$id];
			return true;
		} else {
			return false;
		}
	}
	function Validate($sUserCode, $bCaseInsensitive = true, $key_session = null) {
		if ($bCaseInsensitive) {
			$sUserCode = strtoupper ( $sUserCode );
		}
		
		if (! empty ( $_SESSION [CAPTCHA_SESSION_ID . $key_session] ) && $sUserCode == $_SESSION [CAPTCHA_SESSION_ID . $key_session]) {
			// clear to prevent re-use
			
			if(!$key_session){
				unset($_SESSION[CAPTCHA_SESSION_ID.$key_session]);
			}
		
			return true;
		}
		
		return false;
	}
}